<!--{include admin/top.html}-->
	<div class="mainPage">
	<!--{if $act == 'index'}-->
<script>
	var pID = 0;
	var pObj = null;
	function showSub(Id,obj){
		if(parseInt(Id) == pID){
			$(".sub"+Id).hide();
			$(obj).text('+ 查看');
			pID = 0;
			pObj = null;
		}else{
			$(".sub"+pID).hide();
			$(".sub"+Id).show();
			$(obj).text('- 收起');
			pID = Id;
			if(pObj!=null){
				$(pObj).text('+ 查看');
			}
			pObj = obj;
		}
	}
	// AJAX FUNC //
	function upSort(ov,val,id,obj){
		if(!isNum(val)){
			obj.value = ov;
			return false;
		}
		ov = parseInt(ov);
		val = parseInt(val);
		if(ov == val){
			return false; 
		}
		var url = '{:parse_uri("admin_other-ajax-do-catsort-id-#id#-val-#val#")}';
		url = url.replace('#id#',id).replace('#val#',val);
		$.get(url, function(data){
			if(parseInt(data)==250){
				location.reload();
			}
		});
	}
	function isNum(s){
		var patrn=/^[0-9]{1,3}$/;
		if (!patrn.exec(s)){
			return false;
		}
		return true;
	}
	</script>
	<style>
	.sub_input{
		color:blue;
		font-size:12px;
	}
	</style>
		<h1 class="title">类别列表
			<span class='sub_menu'>
				&nbsp; <a href="{:parse_uri('admin_cat-add')}">添加类别</a>
			</span>
		</h1>
		<table width="100%" align=center cellspacing=0 cellpadding=0 border=0>
		<tr >
			<td width="35%"><p><b>类别名称</b></p></td>
			<td width="15%"><p><b>排序位置</b></p></td>
			<td width="20%"><p><b>封面图片</b></p></td>
			<td width="10%"><p><b>类型</b></p></td>
			<td width="20%"><p><b>操作</b></p></td>
		</tr>
		<!--{foreach $cats $k $v}-->
		<tr class='ctr'>
			<td><p>{$v['cat_name']}<!--{if $v['sub']}-->
				<span style="word-spacing:1px;">[ 
				<a href="javascript:void(0)" onclick="showSub({$v['Id']},this)" style="color:green">+ 查看</a> ]</span>
				<!--{/if}-->
			</p></td>
			<td><p>&nbsp;<input value="{$v['sort']}" class="ipt" style='width:40px;' maxlength='3' onblur="upSort({$v['sort']},this.value,{$v['Id']},this)" /></p></td>
			<td><p>
				{if $v['pic']}
					<img src="{__HOST__}/upload/{:timg($v['pic'])}" height=40 width=60 />
				{else}
					无
				{/if}
			</p></td>
			<td><p>
				{if $v['cat_type']}
					<span style='color:blue'>产品类别</span>
				{else}
					<span style='color:red'>动态类别</span>
				{/if}
			</p></td>
			<td><p>
				<a href="{:parse_uri('admin_cat-modify-id-%d',$v['Id'])}">修改</a> | 
				<a href="{:parse_uri('admin_cat-del-id-%d',$v['Id'])}" onclick="return confirm('确定删除? 操作就删除该类别下所有内容!')">删除</a> | 
				<a href="{:parse_uri('admin_cat-add-pid-%d',$v['Id'])}">添加子类别</a>
			</p></td>
		</tr>
			{foreach $v['sub'] $subk $subv}
				<tr class='ctr sub{$v["Id"]}' style="display:none;" >
					<td>
					<p style="text-algin:left;padding-left:30px;">
					{if $subk === 0 && sizeof($v['sub'])!=1}┌{else if $subk == (sizeof($v['sub'])-1)}└{else}├{/if}
					<span class='sub_cat'>{$subv['cat_name']}</span>
					</p>
					</td>
					<td><p>&nbsp;<input value="{$subv['sort']}" class="ipt sub_input" style='width:40px;' maxlength='3' onblur="upSort({$subv['sort']},this.value,{$subv['Id']},this)" style="" /></p></td>
					<td><p>
						{if $subv['pic']}
							<img src="{__HOST__}/upload/{:timg($subv['pic'])}" height=40 width=60 />
						{else}
							无
						{/if}
					</p></td>
					<td><p>
						{if $subv['cat_type']}
							<span style='color:blue'>产品类别</span>
						{else}
							<span style='color:red'>动态类别</span>
						{/if}
					</p></td>
					<td>
					<p>
						<a href="{:parse_uri('admin_cat-modify-id-%d',$subv['Id'])}">修改</a> | 
				<a href="{:parse_uri('admin_cat-del-id-%d',$subv['Id'])}" onclick="return confirm('确定删除? 操作就删除该类别下所有内容!')">删除</a>
					</p></td>
				</tr>
			{/foreach}
		<!--{/foreach}-->
		</table>
	<!--{else if $act == 'add'|$act == 'modify'}-->
		<h1 class="title">{if  $act == 'add'}添加类别{else}修改 - {$cat['cat_name']}{/if}
			<span class='sub_menu'>
				&nbsp; <a href="{:parse_uri('admin_cat-index')}">返回类别</a>
			</span>
		</h1>
		<form action="{:parse_uri('admin_cat-save')}" id="frm" method="post" enctype="multipart/form-data">
		<p style="line-height:30px;">类别名称: <input class="ipt" id="cat_name" name="cat_name" value="{$cat['cat_name']}"/></p>
		<p style="line-height:30px;">类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;型:&nbsp;&nbsp;&nbsp;
		产品<input type="radio" name="cat_type" value="1" {if $cat['cat_type']=='1'}checked{/if}/> 
		动态<input type="radio" name="cat_type" value="0"  {if $cat['cat_type']=='0'}checked{/if} /></p>
		<p style="line-height:30px;">所属类别: <select name="pid" id="pid" onchange="setCatType(this.options[this.options.selectedIndex])" >
				<option value='none' cat_type='null'>选择所属分类</option>
				<option value='0' cat_type='null'>作为一级分类</option>
				{foreach $cats $k $v}
				<option cat_type="{$v['cat_type']}" value="{$v['Id']}" {if intval($v['Id']) === intval($pid)}selected{/if}>{$v['cat_name']}</option>
				{/foreach}
		</select></p>
		<p style="line-height:30px;">封面图片: <input type="file" name="userFile[]" /></p>
		<p style='margin-top:10px;'>
		<input type="submit" value='提交'class="submit" onclick="return chkFrm()"/>
		<input type="reset" value='重置'class="submit"/>
		<input type="hidden" value='{$cat["Id"]}'name="cat_id"/>
		<input type="hidden" value='{$cat["pic"]}'name="pic"/>
		</p>
		</form>
		<script>
			$(document).ready(function(){
			{if intval($pid) > -1}
			var cat_id = parseInt('{$pid}');
				$("select option").each(function(){
					if(this.value == cat_id){
						this.selected = true;
						setCatType(this);
					}
				});
			{/if}
			});
			function chkFrm(){
				if($("#cat_name").val()==''){
					alert('请输入分类名称!');
					$("#cat_name").focus();
					return false;
				}
				if($("#pid").val()=='none'){
					alert('请选择所属类别!');
					return false;
				}
				var chkval = -1 ;
				$("input[type=radio]").each(function(){
					if(this.checked){
						chkval = this.value;
					}
				});
				if(chkval == -1){
					alert('请设置类别类型!');
					return false;
				}
				return true;
			}
			function setCatType(obj){
				$("input[type=radio]").each(function(){
					if($(obj).attr('cat_type')!='null'){
						if(this.value == $(obj).attr('cat_type')){
							$(this).attr('checked','true');
							$(this).removeAttr('disabled');
						}else{
							$(this).attr('disabled','true');
						}
					}else{
						$(this).removeAttr('disabled');
					}
				});
			}
		</script>
	<!--{/if}-->
	<div align="center" class="runtime"> Processed in {__RUNTIME__} second(s)</div>
	</div>
</body>
</html>